var basePath = getBasePath(); 
var modelName = "消息";
var modelLowClassName = "siteMsg";
var modelUpClassName = "SiteMsg";

$(function(){
	  //显示权限按钮
	  var parentUUID = $("input[name='parentUUID']").val();
   	  $.permission.showButton(parentUUID,"actionBtnArea");
   	  
   	  //表格初始化
	  $.dataGridEasyUI.initTable({
		  pageId:"#"+modelLowClassName+"ListPage",
		  gridId:"#"+modelLowClassName+"List",
		  url:getBasePath()+modelLowClassName+'/get'+modelUpClassName+'List.do',
		  toolbarId:"#"+modelLowClassName+"ListPage .tb_toolbar",
		  columns:[[
  		            {field:'id',checkbox:true},
  		            {field:'title',title:'标题',width:'22%',formatter: function(value,row,index){
	  		  	    	return "<a href='javascript:showDetail("+row.id+")' style='color:green'>"+value+"</a>";
					}},
                    {field:'msgType',title:'消息类型',width:'8%'},
                    {field:'reciveAdminArr',title:'接收人',width:'8%'},
                    {field:'isRead',title:'阅读状态',width:'5%',formatter: function(value,row,index){
                    	if(value==0){
                    		return "<font color='#f58220'><b>未读</b></font>";
                    	}else{
                    		return "<font color='#7fb80e'><b>已读</b></font>";
                    	}
					}},
                    {field:'readCount',title:'阅读量',width:'5%'},
  		            {field:'createTime',title:'消息时间',width:'12%'}
  		        ]]
	  });
  
  //新增按钮绑定事件
  $("#addDataLink").bind("click",function(){
	  $.dataGridEasyUI.initEditWindow({
		  url:getBasePath()+"manage/"+modelLowClassName+"/edit"+modelUpClassName+".jsp",
		  title:"添加"+modelName+"信息",
		  actionType:"add"
	  });
  });
  
  //更新按钮绑定事件
  $("#updateDataLink").bind("click",function(){
	  $.dataGridEasyUI.initEditWindow({
		  url:getBasePath()+"manage/"+modelLowClassName+"/edit"+modelUpClassName+".jsp",
		  title:"编辑"+modelName+"",
		  actionType:"update"
	  });
  });
  
  //批量删除
  $("#batchDeleteLink").bind("click",function(){
	  $.dataGridEasyUI.batchDeleteData({
		  url:getBasePath()+"/"+modelLowClassName+"/batchDel"+modelUpClassName+"ForHS.do",
	  });
  });
  
  //单个删除
  $("#singleDeleteLink").bind("click",function(){
	  $.dataGridEasyUI.batchDeleteData({
		  url:getBasePath()+"/"+modelLowClassName+"/del"+modelUpClassName+".do",
	  });
  });
 
   //图片弹窗
	$(".fancybox-effects-a").fancybox({
		helpers: {
			title : {
				type : 'outside'
			},
			overlay : {
				speedOut : 0
			}
		}
	});
})

//查看详细信息
function showDetail(id){
  $.dataGridEasyUI.initEditWindow({
	  url:getBasePath() + ""+modelLowClassName+"/get"+modelUpClassName+"Detail.do?id="+id,
	  title:"查看"+modelName+"明细",
	  actionType:"detail",
	  width: 650,
	  height: 480
  })
}

//审核信息
function checkSingleData(){
	$.dataGridEasyUI.initEditWindow({
		  url:getBasePath() + "manage/notice/checkNotice.jsp?id=",
		  title:"审核"+modelName,
		  actionType:"check",
	      width: 650,
          height: 300
	});
}

//检索数据
function seachData(){
   var searChObj = new Object(); 
   var formId = "searchForm";
   $("#"+formId).find("input").each(function(i){
	   searChObj[$(this).attr("name")] = $(this).val();
   });
   
   $("#"+formId).find("select").each(function(i){
	   searChObj[$(this).attr("name")] = $(this).val();
   });
   tableObject.datagrid({
	     queryParams:searChObj
   })
}

//永久删除数据
function batchDelInDB(){
  $.dataGridEasyUI.batchDeleteInDB({
	  url:getBasePath()+"/"+modelLowClassName+"/batchDel"+modelUpClassName+".do",
  });
}
         
         
 //恢复数据
function rebackData(){
	$.dataGridEasyUI.batchDeleteInDB({
		  url:basePath+"/"+modelLowClassName+"/batchRebackData.do"
	});
}
